<template>
  <span style="font-size: 13px">{{ content }}</span>
</template>

<script>
export default {
  data () {
    return {
      content: '',
    }
  },
  props: {
    date: {
      type: String,
      default: new Date().toString()
    },
    time: {
      type: Number,
      default: 0,
      dateTimeStamp: ''
    }
  },
  mounted() {
    this.diffTime()
  },
  methods: {
    diffTime () {
      this.dateTimeStamp = this.time
      if (!this.dateTimeStamp) {
        if(!this.date) {
          return '刚刚'
        }
        this.dateTimeStamp = new Date(this.date).getTime()
      }
      let minute = 1000 * 60;
      let hour = minute * 60;
      let day = hour * 24;
      let month = day * 30;
      let now = new Date().getTime();
      let diffValue = now - this.dateTimeStamp;
      if (diffValue <= 1000){
        this.content="刚刚"
        return
      }
      let monthC =diffValue/month;
      let dayC =diffValue/day;
      let hourC =diffValue/hour;
      let minC =diffValue/minute;
      if (parseInt(monthC) >=1) {
        this.content = parseInt(monthC) + '个月前'
      } else if (parseInt(dayC) > 1) {
        this.content = parseInt(dayC) + '天前'
      } else if (parseInt(dayC) === 1) {
        this.content = '昨天'
      } else if(parseInt(hourC)>=1){
        this.content = parseInt(hourC) +"小时前";
      } else if(parseInt(minC)>=1){
        this.content = parseInt(minC) +"分钟前";
      } else {
        this.content = "刚刚";
      }
    }
  }
}
</script>

<style>

</style>